package cn.edu.nju.oraldefense.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import cn.edu.nju.oraldefense.dao.GraduateOperationDao;
import cn.edu.nju.oraldefense.model.Graduate;
import cn.edu.nju.oraldefense.model.GraduateOperation;

@Component("graduateOperationDao")
public class GraduateOperationDaoImpl implements GraduateOperationDao {

	HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public void save(GraduateOperation instance) {
		hibernateTemplate.save(instance);
	}

	public List findByProperty(String propertyName, Object value) {
		String queryString = "from GraduateOperation as model where model."
				+ propertyName + "=? order by time desc";
		return hibernateTemplate.find(queryString, value);
	}

	public List findByGraduateAndTypeAndMonth(Graduate graduate, int type,
			String yearmonth, String nextyearmonth) {
		String queryString = "from GraduateOperation as model where model.type="
				+ type
				+ " and model.time>='"
				+ yearmonth
				+ "' and model.time<'"
				+ nextyearmonth
				+ "'and model.graduate=?";
		return hibernateTemplate.find(queryString, graduate);
	}

}
